/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelVisualProcessorConfiguration.java
 *
 * Created on 22.12.2009, 18:03:33
 */

package de.jmda.mproc.swingui;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractListModel;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import de.jmda.gui.swing.mvc.ControllerContextProvider;
import de.jmda.gui.swing.mvc.ControllerSupportEnabled;

/**
 *
 */
@ControllerSupportEnabled
public class JPanelVisualProcessorConfiguration
    extends javax.swing.JPanel implements ControllerContextProvider
{
	/** Creates new form JPanelVisualProcessorConfiguration */
	private JPanelVisualProcessorConfiguration()
	{
		initComponents();
	}

	/** Creates new form JPanelVisualProcessorConfiguration */
	public JPanelVisualProcessorConfiguration(
			JPanelVisualProcessorConfigurationModel
					jPanelVisualProcessorConfigurationModel)
	{
		this();
		controller.refreshControllerContext();
		controller.setModel(jPanelVisualProcessorConfigurationModel);
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {
		GridBagConstraints gridBagConstraints;

    jSplitPaneMain = new JSplitPane();
    jPanelLeft = new JPanel();
    jScrollPaneConfigurations = new JScrollPane();
    jListConfigurations = new JList();
    jButtonNew = new JButton();
    jButtonDelete = new JButton();
    jButtonSave = new JButton();
    jPanelRight = new JPanel();

    setPreferredSize(new Dimension(800, 600));
    setLayout(new GridBagLayout());

    jSplitPaneMain.setOneTouchExpandable(true);

    jPanelLeft.setBorder(BorderFactory.createTitledBorder("configurations"));
    jPanelLeft.setLayout(new GridBagLayout());

    jListConfigurations.setModel(new AbstractListModel() {
      String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
      public int getSize() { return strings.length; }
      public Object getElementAt(int i) { return strings[i]; }
    });
    jListConfigurations.addListSelectionListener(new ListSelectionListener() {
      public void valueChanged(ListSelectionEvent evt) {
        jListConfigurationsValueChanged(evt);
      }
    });
    jScrollPaneConfigurations.setViewportView(jListConfigurations);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    jPanelLeft.add(jScrollPaneConfigurations, gridBagConstraints);

    jButtonNew.setText("new");
    jButtonNew.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        jButtonNewActionPerformed(evt);
      }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = GridBagConstraints.EAST;
    gridBagConstraints.weightx = 1.0;
    jPanelLeft.add(jButtonNew, gridBagConstraints);

    jButtonDelete.setText("delete");
    jButtonDelete.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        jButtonDeleteActionPerformed(evt);
      }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.weightx = 1.0;
    jPanelLeft.add(jButtonDelete, gridBagConstraints);

    jButtonSave.setText("save");
    jButtonSave.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        jButtonSaveActionPerformed(evt);
      }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    jPanelLeft.add(jButtonSave, gridBagConstraints);

    jSplitPaneMain.setLeftComponent(jPanelLeft);

    jPanelRight.setBorder(BorderFactory.createTitledBorder("active configuration"));
    jPanelRight.setLayout(new GridBagLayout());
    jSplitPaneMain.setRightComponent(jPanelRight);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    add(jSplitPaneMain, gridBagConstraints);
  }// </editor-fold>//GEN-END:initComponents

	private void jButtonNewActionPerformed(ActionEvent evt)//GEN-FIRST:event_jButtonNewActionPerformed
	{//GEN-HEADEREND:event_jButtonNewActionPerformed
		controller.newActionPerformed(evt);
	}//GEN-LAST:event_jButtonNewActionPerformed

	private void jButtonDeleteActionPerformed(ActionEvent evt)//GEN-FIRST:event_jButtonDeleteActionPerformed
	{//GEN-HEADEREND:event_jButtonDeleteActionPerformed
		controller.deleteActionPerformed(evt);
	}//GEN-LAST:event_jButtonDeleteActionPerformed

	private void jButtonSaveActionPerformed(ActionEvent evt)//GEN-FIRST:event_jButtonSaveActionPerformed
	{//GEN-HEADEREND:event_jButtonSaveActionPerformed
		controller.saveActionPerformed(evt);
	}//GEN-LAST:event_jButtonSaveActionPerformed

	private void jListConfigurationsValueChanged(ListSelectionEvent evt)//GEN-FIRST:event_jListConfigurationsValueChanged
	{//GEN-HEADEREND:event_jListConfigurationsValueChanged
		controller.configurationsValueChanged(evt);
	}//GEN-LAST:event_jListConfigurationsValueChanged

	/**
	 * @param args the command line arguments
	 */
	public static void main(final String args[])
	{
//		try
//		{
//			UIManager.setLookAndFeel(NimbusLookAndFeel.class.getName());
//			UIManager.setLookAndFeel(WindowsLookAndFeel.class.getName());
//			UIManager.setLookAndFeel(PlasticLookAndFeel.class.getName());
//		}
//		catch (Exception e)
//		{
			try
      {
	      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      }
      catch (Exception e1)
      {
      	System.err.println("failure setting system look and feel, aborting");
      	return;
      }
//		}

		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				JFrame jFrame =
				    new JFrame(
				    		"jMDA Annotation Processing Configuration Launcher");

				jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

				jFrame.add(
						new JPanelVisualProcessorConfiguration(
								new JPanelVisualProcessorConfigurationModel()));

				jFrame.pack();
				jFrame.setLocationRelativeTo(null);
				jFrame.setVisible(true);
			}
		});
	}

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private JButton jButtonDelete;
  private JButton jButtonNew;
  private JButton jButtonSave;
  private JList jListConfigurations;
  private JPanel jPanelLeft;
  private JPanel jPanelRight;
  private JScrollPane jScrollPaneConfigurations;
  private JSplitPane jSplitPaneMain;
  // End of variables declaration//GEN-END:variables

	//GEN-BEGIN:controller support
	@de.jmda.gui.swing.mvc.ControllerSupportDisabled                     
	private de.jmda.mproc.swingui.JPanelVisualProcessorConfigurationController controller =                       
			new de.jmda.mproc.swingui.JPanelVisualProcessorConfigurationController(this);                             
                                                                         
	public de.jmda.gui.swing.mvc.ControllerContext getControllerContext()
	{                                                                      
		return new de.jmda.mproc.swingui.JPanelVisualProcessorConfigurationControllerContext(
				this,
				jButtonDelete,
				jButtonNew,
				jButtonSave,
				jListConfigurations,
				jPanelLeft,
				jPanelRight,
				jScrollPaneConfigurations,
				jSplitPaneMain);                             
	}                                                                      
	//GEN-END:controller support
}